using System;
using Android.Locations;

namespace MapDrawer
{
    [Serializable]
    public class Point
    {
        public Coordinate Coordinates { get; set; }
        private float _speed;
        public float Speed
        {
            get { return _speed; }
            set
            {
                _speed = value;
                HasSpeed = true;
            }
        }
        public bool HasSpeed { get; set; }
        private float _altitude;
        public float Altitude 
        {
            get { return _altitude; }
            set 
            { 
                _altitude = value;
                HasAltitude = true;
            } 
        }
        public bool HasAltitude { get; set; }

        public Point()
        {
            HasSpeed = false;
            HasAltitude = false;
        }

        public Point(Location l)
        {
            Coordinates = new Coordinate((float) l.Latitude, (float) l.Longitude);
            if (l.HasAltitude)
            {
                Altitude = (float) l.Altitude;
                HasAltitude = true;
            }
            if (l.HasSpeed)
            {
                Speed = l.Speed;
                HasSpeed = true;
            }
        }

        public string Json ()
        {
            var json = "{";
            json += "\"Longitude\" : ";
            json += Coordinates.Longitude;
            json += " , ";
            json += "\"Latitude\" : ";
            json += Coordinates.Latitude;
            json += " , ";
            json += "\"HasAltitude\" : ";
            json += HasAltitude;
            json += " , ";
            json += "\"Altitude\" : ";
            json += Altitude;
            json += " , ";
            json += "\"HasSpeed\" : ";
            json += HasSpeed;
            json += " , ";
            json += "\"Speed\" : ";
            json += Speed;
            json += "}";
            return json;
        }
    }
}